﻿/**********************************************************************
*创建人：蔡水明
*创建时间：2018/3/18 18:18:40
*说明：<Function>
/**********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Utilities
{
    public static class WindowsHelper
    {
        /// <summary>
        /// 闪烁窗口
        /// </summary>
        /// <param name="pwfi">窗口闪烁信息结构</param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
        /// <summary>
        /// 闪烁窗口
        /// </summary>
        /// <param name="hWnd">窗口句柄</param>
        /// <param name="type">闪烁类型</param>
        /// <returns></returns>
        public static bool FlashWindowEx(IntPtr hWnd, flashType type)
        {
            FLASHWINFO fInfo = new FLASHWINFO();
            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = hWnd;//要闪烁的窗口的句柄，该窗口可以是打开的或最小化的
            fInfo.dwFlags = (uint)type;//闪烁的类型
            fInfo.uCount = UInt32.MaxValue;//闪烁窗口的次数
            fInfo.dwTimeout = 0; //窗口闪烁的频度，毫秒为单位；若该值为0，则为默认图标的闪烁频度
            return FlashWindowEx(ref fInfo);
        }
    }
    /// <summary>
    /// 闪烁类型
    /// </summary>
    public enum flashType : uint
    {
        FLASHW_STOP = 0, //停止闪烁
        FALSHW_CAPTION = 1, //只闪烁标题
        FLASHW_TRAY = 2, //只闪烁任务栏
        FLASHW_ALL = 3, //标题和任务栏同时闪烁
        FLASHW_PARAM1 = 4,
        FLASHW_PARAM2 = 12,
        FLASHW_TIMER = FLASHW_TRAY | FLASHW_PARAM1, //无条件闪烁任务栏直到发送停止标志或者窗口被激活，如果未激活，停止时高亮
        FLASHW_TIMERNOFG = FLASHW_TRAY | FLASHW_PARAM2 //未激活时闪烁任务栏直到发送停止标志或者窗体被激活，停止后高亮
    }
    /// <summary>
    /// 包含系统应在指定时间内闪烁窗口次数和闪烁状态的信息
    /// </summary>
    public struct FLASHWINFO
    {
        /// <summary>
        /// 结构大小
        /// </summary>
        public uint cbSize;
        /// <summary>
        /// 要闪烁或停止的窗口句柄
        /// </summary>
        public IntPtr hwnd;
        /// <summary>
        /// 闪烁的类型
        /// </summary>
        public uint dwFlags;
        /// <summary>
        /// 闪烁窗口的次数
        /// </summary>
        public uint uCount;
        /// <summary>
        /// 窗口闪烁的频度，毫秒为单位；若该值为0，则为默认图标的闪烁频度
        /// </summary>
        public uint dwTimeout;
    }
}
